package com.mdd.front.controller.yangyangLeadingEnterprise.index;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppPublicWelfareProject;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.dto.AppPublicWelfareProjectDTO;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.PublicWelfareProjectParam;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppPublicWelfareProjectService;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppUserPublicWelfareService;
import com.mdd.front.validate.yangyangLeadingEnterprise.TAppUserPublicWelfareCreateValidate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

//@ApiIgnore
@RestController
@RequestMapping("api.index/publicWelfareProject")
@Api(tags = "app首页---领企公益页面")
public class TAppPublicWelfareProjectController {

    @Resource
    ITAppPublicWelfareProjectService appPublicWelfareProjectService;

    @Resource
    ITAppUserPublicWelfareService appUserPublicWelfareService;

    @NotLogin
    @PostMapping(value = "/index",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="领企公益页面")
    public String index(HttpServletRequest request) {
        //精选项目
        PublicWelfareProjectParam param = new PublicWelfareProjectParam();
        //todo 后台管理完成之后进行数量进行调控
//        param.setAmount(1);
        param.setOrderByType(1);
        param.setType(1);
        List<AppPublicWelfareProjectDTO> projectList=appPublicWelfareProjectService.selectList(param);
//        List<Integer> idPks = projectList.parallelStream().map(AppPublicWelfareProjectDTO::getId).collect(Collectors.toList());
        //其他项目
        PublicWelfareProjectParam paramData = new PublicWelfareProjectParam();
//        paramData.setAmount(null);
        paramData.setOrderByType(1);
//        paramData.setIdPks(idPks);
        paramData.setType(2);
        List<AppPublicWelfareProjectDTO> OthersProjectList=appPublicWelfareProjectService.selectList(paramData);
        return JsonReturn.success()
                .put("projectList",projectList)
                .put("OthersProjectList",OthersProjectList)
                .toJsonStr();
    }

//    @GetMapping("/selectList111")
//    @ApiOperation(value="帮助他")
//    public String selectList1111(PublicWelfareProjectParam param) {
//        return  appPublicWelfareProjectService.selectList(param);
//    }

//    @Log(title = "用户捐赠公益项目新增")
    @ApiIgnore
    @PostMapping(value = "/addUserPublicWelfare",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="用户捐赠公益项目新增")
    public String add(@Validated @RequestBody TAppUserPublicWelfareCreateValidate createValidate) {
        //todo 捐赠成功之后增加捐赠次数
        return appUserPublicWelfareService.addUserPublicWelfare(createValidate);
    }


}
